<?php

namespace App\Http\Middleware;

use App\Services\Link;
use Closure;

/**
 * 此中间件用于检查节点版 UAC 是否已与中心版建立关联，未成功建立关联时，直接跳转到关联界面中。
 */
class CheckLink
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $data = app('link')->getLinkData();
        if ($data['state'] != Link::LINK_STATE_SUCCESS) {
            return redirect()->route('links.index');
        }
        return $next($request);
    }
}
